RStudio has many data sets already loaded in. The example below uses preloaded data direct from RStudio example dataset: mtcars.
Read about the mtcars data set.
In the rmd file, you will see how you can load your own dataset from either 1) an online source using a URL or 2) a local file on your own computer.
# LOAD DATA v1 - uncomment the link below to: load data direct from html
#cars = read.csv("dataset URL")
# LOAD DATA v2 - uncomment the link below to: load data from local file
#cars = read.csv("dataset file location")
# Quick look at top 5 rows of data
head(mtcars)
## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
## Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
## Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
## Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
## Size of data
# For the mtcars dataset, there are 32 rows (the types of cars) and 11 variables (properties of the cars).
dim(mtcars)
## [1] 32 11
## R's classification of data
class(mtcars)
## [1] "data.frame"
## R's classification of variables
str(mtcars)
## 'data.frame': 32 obs. of 11 variables:
## $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
## $ cyl : num 6 6 4 6 8 6 8 4 4 6 ...
## $ disp: num 160 160 108 258 360 ...
## $ hp : num 110 110 93 110 175 105 245 62 95 123 ...
## $ drat: num 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
## $ wt : num 2.62 2.88 2.32 3.21 3.44 ...
## $ qsec: num 16.5 17 18.6 19.4 17 ...
## $ vs : num 0 0 1 1 0 1 0 1 1 1 ...
## $ am : num 1 1 1 0 0 0 0 0 0 0 ...
## $ gear: num 4 4 4 3 3 3 3 4 4 4 ...
## $ carb: num 4 4 1 1 2 1 4 2 2 4 ...
#sapply(mtcars, class)
Summary:
Insert text and analysis.
Summary:
Insert text and analysis.
Summary:
Style: APA
This quick reference guide will cover some basic RMarkdown for use in your projects.
Here is a basic list:
To do 1
To do 2
To do 3
Here is a simple table.
| Tables | Are | Cool |
|---|---|---|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
Here is am image. It has not been adjusted in the rmd file, so represents the true size of the original image. This image is sourced directly from an online url.
To learn more about adding images directly from your own computer, see the comments in this rmd file.
Image source: https://petcube.com/blog/10-all-important-kitten-supplies-infographic/
Below you will find a video embedded into your RMarkdown file. Change the YouTube link in the rmd file to get a different video.
You can even use LaTeX in an RMarkdown document!
For example, how could you work out \(\sum_{i=1}^{5} x_{i}^3\)?
Here is an R code chunk:
Try the following commands in R.
1+ exp(3) + sin(0.5)
x=c(1,2,3)
x^2
sum(x)
Here is some in-line code in-line code. You can put any R code here for display, e.g. sum(x)
Check out the resources below for more information on RMarkdown.